<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
 <head>
  <title>Keystone VAS Administrator</title>
	<style type="text/css">
		@import "/js/dijit/themes/tundra/tundra.css";
		@import "/js/dojox/grid/resources/tundraGrid.css";
		@import "/js/dojox/form/resources/DropDownSelect.css";
		@import "/css/keystoneadmin.css";
	</style>
<style>
.tundra .dojoxGridCell {
font-family:Verdana,Arial,Helvetica,sans-serif;
font-size: 9pt !important;
}
</style>
<script type="text/javascript" src="/js/dojo/dojo.js" djConfig="parseOnLoad:true, isDebug:true"></script>

<script type="text/javascript">

    dojo.require('dojo.data.ItemFileReadStore');
    dojo.require('dojox.grid.DataGrid');
    dojo.require('dijit.form.Button');
    dojo.require('dijit.Dialog');
    dojo.require('dojo.parser');

    var funeralDirsQueryBaseUrl = 'http://www.aldordemo.com/index/ksfuneraldirectors/funeral_home_id/';
    var funeralCasesQueryBaseUrl = 'http://www.aldordemo.com/index/kscases/funeral_dir_id/';

    var funeralDirsQueryUrl = funeralDirsQueryBaseUrl + '0';
    var funeralCasesQueryUrl = funeralCasesQueryBaseUrl + '0';

    var funeralHomeStore = new dojo.data.ItemFileReadStore({ url: "http://www.aldordemo.com/index/ksfuneralhomes" });
    var funeralDirectorStore = new dojo.data.ItemFileReadStore({ url: funeralDirsQueryUrl });
    var funeralCasesStore = new dojo.data.ItemFileReadStore({ url: funeralCasesQueryUrl });
    var priorityMerchStore = new dojo.data.ItemFileReadStore({ url: "http://www.aldordemo.com/index/ksmerchandise/" });
    var cashAdvancesStore = new dojo.data.ItemFileReadStore({ url: "http://www.aldordemo.com/index/kscashadvances/" });
 
// functions to reload Dojo grids dynamically

    function loadFuneralDirectorsForFH( fh_id )
    {
	var newFDstoreUrl = funeralDirsQueryBaseUrl + fh_id;
	var newFuneralDirectorStore = new dojo.data.ItemFileReadStore({ url: newFDstoreUrl });
	funeralDirectorsGrid.setStore(newFuneralDirectorStore);
	delete funeralDirectorStore;
	funeralDirectorStore = newFuneralDirectorStore;
	funeralDirectorsGrid._refresh();
    }

    function loadCasesForFD( fd_id )
    {
	// display a "getting data" modal dialog
	var newFuneralCasesQueryUrl = funeralCasesQueryBaseUrl + fd_id;
	var newFuneralCasesStore = new dojo.data.ItemFileReadStore({ url: newFuneralCasesQueryUrl });
	funeralCasesGrid.store = newFuneralCasesStore;
	funeralCasesGrid._refresh();
	delete funeralCasesStore;
	funeralCasesStore = newFuneralCasesStore;
	// dismiss the dialog
    }

// functions to get selected funeral home / funeral director name

    function getSelectedFuneralHomeName()
    {
	var items = funeralHomesGrid.selection.getSelected();
	if(items.length != 1) return -1;

	var selectedItem = items[0];
	var fhname = funeralHomesGrid.store.getValues(selectedItem, 'name');
	
	return fhname;
    }

    function getSelectedFuneralHomeCityState()
    {
	var items = funeralHomesGrid.selection.getSelected();
	if(items.length != 1) return -1;

	var selectedItem = items[0];
	var fhcitystate = funeralHomesGrid.store.getValues(selectedItem, 'citystate');
	
	return fhcitystate;
    }

    function getSelectedFuneralDirectorName()
    {
	var items = funeralDirectorsGrid.selection.getSelected();
	if(items.length != 1) return -1;

	var selectedItem = items[0];
	var fdname = funeralDirectorsGrid.store.getValues(selectedItem, 'name');
	
	return fdname;
    }

// functions to enable/disable select buttons
    function disableFHselectButton()
    {
    }

    function enableFHselectButton()
    {
    }

    function disableFDselectButton()
    {
    }

    function enableFDselectButton()
    {
    }


// functions to grab IDs from grids.  these are needed to make the lists change when the [Select] buttons get clicked
// or we need to edit/review the data represented by a particular row

    function getSelectedFuneralHomeId()
    {
	var items = funeralHomesGrid.selection.getSelected();
	if(items.length != 1) return -1;

	var selectedItem = items[0];
	var fhid = funeralHomesGrid.store.getValues(selectedItem, 'funeral_home_id');
	
	return fhid;
    }

    function getSelectedFuneralDirectorId()
    {
	var items = funeralDirectorsGrid.selection.getSelected();
	if(items.length != 1) return -1;

	var selectedItem = items[0];
	var fdid = funeralDirectorsGrid.store.getValues(selectedItem, 'id');
	
	return fdid;
    }

    function getSelectedCaseId()
    {
	var items = funeralCasesGrid.selection.getSelected();
	if(items.length != 1) return -1;
	var selectedItem = items[0];
	var casenum = funeralCasesGrid.store.getValues(selectedItem, 'case_num');	
	return casenum;
    }

// functions called when "Select" button is clicked in the FD and Case lists, respectively
    function updateFuneralDirectorGrid( fh_id )
    {
	// set directors data store URL to use fh_id so we get back directors for funeral home fh_id
	alert('getting funeral directors for funeral home '+fh_id);
    }

    function updateCaseGrid( fd_id )
    {
	// set cases data store URL to use fd_id so we get back directors for funeral dir fd_id
	alert('getting cases for funeral home '+fd_id);
    }

// functions called to enable/disable Select and Edit buttons when there are/are not contents in the grids
    function enableFDButtons( yesNo )
    {
    }

    function enableCaseButtons( yesNo )
    {
    }

// button click handlers for Funeral Homes grid
    function fhGridImportBtnClick( )
    {
	// 1. clear out FH, FD, cases grids (for FD and cases grids, reassign URLs to use ID 0)
	// 2. make method call to index/import_FHs
	// 3. reload FH grid and blank out 
	alert('Updating local list of Keystone Funeral Homes by importing from FDMS');
    }

    function fhGridSelectBtnClick( )
    {
	var fh_id = getSelectedFuneralHomeId();
	loadFuneralDirectorsForFH(fh_id);
	funeralDirectorsGrid.selection.deselectAll();
	funeralDirectorsGrid.update();
	loadCasesForFD('0');
	var selFHname = getSelectedFuneralHomeName();
	document.getElementById('fhName').innerHTML = selFHname;
    }

    function fhGridReviewBtnClick( )
    {
	var fh_id = getSelectedFuneralHomeId();
	alert('Review/update profile info for FH id='+fh_id);
	// 1. grab the selected funeral home from the list
	// 2. go to display page.
    }

// button click handlers for Funeral Directors grid

    function fdGridImportBtnClick( )
    {
	var fh_id = getSelectedFuneralHomeId();
	alert('Synchronizing FDs with FDMS for FH id='+fh_id);
    }

    function fdGridSelectBtnClick( )
    {
	var fd_id = getSelectedFuneralDirectorId();
	loadCasesForFD(fd_id);
	funeralCasesGrid.selection.deselectAll();
	var selFDname = getSelectedFuneralDirectorName();
	document.getElementById('fdName').innerHTML = selFDname;
    }

    function fdGridReviewBtnClick( )
    {
	var selFDname = getSelectedFuneralDirectorName();
	alert('Review profile of FD: ' + selFDname);
    }

// button click handler for Cases grid 'review' button

    function fdCaseReviewBtnClick( )
    {
	var selCaseID = getSelectedCaseId();
	if( selCaseID < 1 )
		alert('no case selected');
	else
		alert('Review case '+selCaseID);
    }

// grid row click handlers to enable the Review/Select buttons

    function fhGridRowClick(row)
    {
	// enables the Review and Select buttons. NOTE - need to hook this up to the grid.
	//dojo.byId('btnFHreview').disabled = false;
	//dojo.byId('btnFHselect').disabled = false;
    }

    function fdGridRowClick(row)
    {
	// enables the Review and Select buttons. NOTE - need to hook this up to the grid.
    }

    function caseGridRowClick(row)
    {
	// enables the Review button
    }

// serious Dojo begins here

    dojo.addOnLoad( function() {

	    funeralHomesGrid = new dojox.grid.DataGrid({
		query: { funeral_home_id: '*' },
		store: funeralHomeStore,
		structure: [
		    { field: "funeral_home_id", name: "ID", width:"80px" },
		    { field: "name", name: "Name", width:"auto" },
		    { field: "citystate", name: "City, State", width:"auto" }
		],
		rowsPerPage: 3,
		selectionMode: 'single'
		}, 'funeralHomesGrid');

	    funeralDirectorsGrid = new dojox.grid.DataGrid({
		query: { id: '*' },
		store: funeralDirectorStore,
		structure: [
		    { field: "id", name: "ID", width:"80px" },
		    { field: "name", name: "Name", width:"auto" }
		],
		rowsPerPage: 3,
		selectionMode: 'single'
		}, 'funeralDirectorsGrid');

	    funeralCasesGrid = new dojox.grid.DataGrid({
		query: { case_num: '*' },
		store: funeralCasesStore,
		structure: [
		    { field: "case_num", name: "Case ID", width:"100px" },
		    { field: "status", name: "Status", width:"auto" },
		    { field: "name", name: "Name", width:"auto" },
		    { field: "dob", name: "Born", width:"auto" },
		    { field: "dod", name: "Died", width:"auto" },
		    { field: "residence", name: "Resided In", width:"auto" },
		],
		rowsPerPage: 3,
		selectionMode: 'single'
		}, 'funeralCasesGrid');

	    priorityMerchGrid = new dojox.grid.DataGrid({
		query: { id: '*' },
		store: priorityMerchStore,
		structure: [
		    { field: "rank", name: "Rank", width:"30px" },
		    { field: "region", name: "Region", width:"60px" },
		    { field: "FDMS_product_code", name: "FDMS SKU", width:"auto" },
		    { field: "product_description", name: "Description", width:"auto" },
		],
		rowsPerPage: 3,
		selectionMode: 'single'
		}, 'priorityMerchGrid');

	    cashAdvancesGrid = new dojox.grid.DataGrid({
		query: { id: '*' },
		store: cashAdvancesStore,
		structure: [
		    { field: "id", name: "CaID", width:"50px" },
		    { field: "region", name: "Region", width:"auto" },
		    { field: "area", name: "Area", width:"auto" },
		    { field: "name", name: "Descr", width:"200px" },
		    { field: "amt", name: "Amt", width:"auto" },
		],
		rowsPerPage: 3,
		selectionMode: 'single'
		}, 'cashAdvancesGrid');

		funeralHomesGrid.startup();
		funeralDirectorsGrid.startup();
		funeralCasesGrid.startup();
		priorityMerchGrid.startup();
		cashAdvancesGrid.startup();

	});
</script>    

 </head>
 <body>

<div id="dialog1" jsId="dialog1" lodojoTYpe="dijit.Dialog" title="Getting Data">
<div>
Fetching data.  Please wait.
</div>
</div>

 <table border=0 cellpadding=0>
    <tr>
        <td><img src="/art/keystone_logo2.jpg"></td>
        <td width=50% align=center>Keystone Holdings, Inc.<br><h1>Virtual Arrangement System</h1></td>
        <td width=25%><i>Administrator:</i><br>Carla M Hills</td>
    </tr>
 </table>

 <table border=0 width=1000px>
    <tr>
        <td>
	    <div class="tundra">
		    <h1>Funeral Homes</h1>
		    <div class="gridContainer">
			    <div id="funeralHomesGrid">
			    </div>
		    </div>
		    <div style='width:450; align:right'>
	   	    <button id="btnFHimport" jsId="btnFHimport" dojoType="dijit.form.Button" onClick='fhGridImportBtnClick' style='font-size:9pt'>Import</button>
		    <button id="btnFHreview" jsId="btnFHreview" dojoType="dijit.form.Button" onClick='fhGridReviewBtnClick' style='font-size:9pt'>Review</button>
		    <button id="btnFHselect" jsId="btnFHselect" dojoType="dijit.form.Button" onClick='fhGridSelectBtnClick' style='font-size:9pt'>Select</button> 
		    </div>
	    </div>
        </td>
	<td>
	    <div  class="tundra">
		    <h1>Top Merchandise</h1>
		    <div class="gridContainer">
			    <div id="priorityMerchGrid">
			    </div>
		    </div>
		    <button id="btnPMedit" dojoType="dijit.form.Button" style='font-size:9pt'>Edit Top Merchandise</button>
	    </div>
	</td>
    </tr>
    <tr>
        <td>
	    <div  class="tundra">
		    <h1>Funeral Directors: <span id='fhName' jsId='fhName' style='text-weight:bold'></span></h1>
		    <div class="gridContainer">
			    <div id="funeralDirectorsGrid">
			    </div>
		    </div>
		    <button id="btnFDimport" dojoType="dijit.form.Button" onClick='fdGridImportBtnClick' style='font-size:9pt'>Import</button>
		    <button id="btnFDreview" dojoType="dijit.form.Button" onClick='fdGridReviewBtnClick' style='font-size:9pt'>Review</button>
		    <button id="btnFDselect" dojoType="dijit.form.Button" onClick='fdGridSelectBtnClick' style='font-size:9pt'>Select</button>
	   </div>
        </td>

	<td>
	    <div  class="tundra">
		    <h1>Cash Advances</h1>
		    <div class="gridContainer">
			    <div id="cashAdvancesGrid">
			    </div>
		    </div>
		    <button id="btnCAedit" dojoType="dijit.form.Button" style='font-size:9pt'>Edit Cash Advances</button>
	   </div>
	</td>
  </tr>
    <tr>
        <td>
	    <div  class="tundra">
		    <h1>Current Cases: <span id='fdName' jsId='fdName'></span></h1>
		    <div class="gridContainer">
			    <div id="funeralCasesGrid">
			    </div>
		    </div>
		    <button id="btnCASEreview" dojoType="dijit.form.Button" onClick='fdCaseReviewBtnClick' style='font-size:9pt'>Review</button>
	   </div>
       </td>
    </tr>
</table> 
</body>

</html>
